package com.example.meitao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.meitao.R;
import com.example.meitao.bean.Detail;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 星星 on 2016/8/30.
 */
public class DetailAdapter extends BaseAdapter{
    private List<Detail.Databean.Subentitybean> data;
    private Context context;

    public DetailAdapter(List<Detail.Databean.Subentitybean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data==null?0:data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final MyViewHolder holder;
        if(view==null) {
            view = LayoutInflater.from(context).inflate(R.layout.detail_item,null);
            holder = new MyViewHolder(view);
            view.setTag(holder);
        }else{
            holder = (MyViewHolder) view.getTag();
        }
        holder.t1.setText(data.get(i).getEname());
        holder.t2.setText(data.get(i).getCurrency_symbol()+data.get(i).getPrice()+"元");
        holder.t3.setText(data.get(i).getLabels().get(0));
        holder.t4.setText(data.get(i).getEditorcomment().getComments());
        Picasso.with(context).load(data.get(i).getEntitypicv2().get(0).getFilename()).into(holder.mImageView);
        return view;
    }
    public static class MyViewHolder{
        private ImageView mImageView;
        private TextView t1,t2,t3,t4;
        public MyViewHolder(View view) {
            mImageView = (ImageView) view.findViewById(R.id.iv_detail_item_show);
            t1 = (TextView) view.findViewById(R.id.tv_item_discount_title);
            t2 = (TextView) view.findViewById(R.id.tv_detial_item_money);
            t3 = (TextView) view.findViewById(R.id.tv_detial_item_biaoqian);
            t4 = (TextView) view.findViewById(R.id.tv_detial_item_neirong);
        }
    }
}
